//
//  BoZeDetailHeaderView.swift
//  BoZeCalendar
//
//  Created by 李东 on 2024/4/12.
//

import UIKit
import SnapKit

class BoZeDetailHeaderView: UIView {
    
    lazy var contentView = UIView()
    lazy var leftLabel1 = UILabel()
    lazy var leftLabel2 = UILabel()
    lazy var midLabel1 = UILabel()
    lazy var midLabel2 = UILabel()
    lazy var rightLabel1 = UILabel()
    lazy var rightLabel2 = UILabel()

    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = .clear
        contentView.backgroundColor = .init(hex: 0x89BB85)
        contentView.layer.cornerRadius = 15
        contentView.layer.masksToBounds = true
        addSubview(contentView)
        contentView.snp.makeConstraints { make in
            make.left.equalTo(20)
            make.right.equalTo(-20)
            make.top.bottom.equalToSuperview()
        }
        
        leftLabel1.font = UIFont.Medium(ofSize: 14)
        leftLabel1.textColor = .black
        leftLabel1.textAlignment = .center
        leftLabel1.text = "总加油(L)"
        contentView.addSubview(leftLabel1)
        leftLabel1.snp.makeConstraints { make in
            make.left.equalToSuperview()
            make.bottom.equalTo(self.snp.centerY).offset(-5)
        }
        midLabel1.font = UIFont.Medium(ofSize: 14)
        midLabel1.textColor = .black
        midLabel1.textAlignment = .center
        midLabel1.text = "总油费(元)"
        contentView.addSubview(midLabel1)
        midLabel1.snp.makeConstraints { make in
            make.left.equalTo(leftLabel1.snp.right)
            make.width.equalTo(leftLabel1)
            make.bottom.equalTo(self.snp.centerY).offset(-5)
        }
        rightLabel1.font = UIFont.Medium(ofSize: 14)
        rightLabel1.textColor = .black
        rightLabel1.textAlignment = .center
        rightLabel1.text = "油耗(L/100km)"
        contentView.addSubview(rightLabel1)
        rightLabel1.snp.makeConstraints { make in
            make.left.equalTo(midLabel1.snp.right)
            make.right.equalToSuperview()
            make.width.equalTo(midLabel1)
            make.bottom.equalTo(self.snp.centerY).offset(-5)
        }
        leftLabel2.font = UIFont.Semibold(ofSize: 28)
        leftLabel2.textColor = .black
        leftLabel2.textAlignment = .center
        leftLabel2.text = "--"
        leftLabel2.adjustsFontSizeToFitWidth = true
        contentView.addSubview(leftLabel2)
        leftLabel2.snp.makeConstraints { make in
            make.left.right.equalTo(leftLabel1)
            make.top.equalTo(self.snp.centerY).offset(5)
        }
        midLabel2.font = UIFont.Semibold(ofSize: 28)
        midLabel2.textColor = .black
        midLabel2.textAlignment = .center
        midLabel2.text = "--"
        midLabel2.adjustsFontSizeToFitWidth = true
        contentView.addSubview(midLabel2)
        midLabel2.snp.makeConstraints { make in
            make.left.right.equalTo(midLabel1)
            make.top.equalTo(self.snp.centerY).offset(5)
        }
        rightLabel2.font = UIFont.Semibold(ofSize: 28)
        rightLabel2.textColor = .black
        rightLabel2.textAlignment = .center
        rightLabel2.text = "--"
        rightLabel2.adjustsFontSizeToFitWidth = true
        contentView.addSubview(rightLabel2)
        rightLabel2.snp.makeConstraints { make in
            make.left.right.equalTo(rightLabel1)
            make.top.equalTo(self.snp.centerY).offset(5)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func configData(allOil: Int, allCost: CGFloat, allConsumption: CGFloat) {
        if allConsumption == 0 {
            rightLabel2.text = "--"
        }else{
            rightLabel2.text = String(format: "%.1f", allConsumption)
        }
        if allOil == 0 {
            leftLabel2.text = "--"
        }else{
            leftLabel2.text = "\(allOil)"
        }
        if allCost == 0 {
            midLabel2.text = "--"
        }else{
            midLabel2.text = String(format: "%.2f", allCost)
        }
    }
    

}
